

package com.googlecode.flac4j.format.frame.sub;


/**
 *
 * @author Jin Kwon <jinahya at gmail.com>
 */
public enum SubFrameType {


    CONSTANT(0), // 000000
    FIXED(1), // 000001
    LPC(0x08, 0x0F), // 001000 - 001111
    VERBATIM(0x20, 0x3F); // 100000 - 111111


    public static SubFrameType valueOf(final int type) {
        for (SubFrameType value : values()) {
            if (value.mathes(type)) {
                return value;
            }
        }

        throw new IllegalArgumentException(
            "no constants matches for type(" + type + ")");
    }


    private SubFrameType(final int type) {
        this(type, type);
    }


    private SubFrameType(final int minimumType, final int maximumType) {

        if (minimumType >> 6 != 0) {
            throw new IllegalArgumentException(
                "minimumType(" + minimumType + ") >> 6 != 0");
        }

        if (maximumType >> 6 != 0) {
            throw new IllegalArgumentException(
                "maximumType(" + maximumType + ") >> 6 != 0");
        }

        if (maximumType < minimumType) {
            throw new IllegalArgumentException(
                "maximumValue(" + maximumType + ") < minimumType("
                + minimumType + ")");
        }

        this.minimumType = minimumType;
        this.maximumType = maximumType;
    }


    public boolean mathes(final int type) {
        return type >= minimumType && type <= maximumType;
    }


    /** minimum value. */
    private final int minimumType;


    /** maximum value. */
    private final int maximumType;


}

